package com.infra.server.webmagic;


import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

/**
 * @author win
 * @date 2021/11/24 15:56
 * 空气质量数据处理
 */
public class KqzlPipeline implements Pipeline {

    public static JSONArray siteData = new JSONArray();
    public static final JSONArray zbData = new JSONArray();

    @Override
    public void process(ResultItems resultItems, Task task) {
        if (ObjectUtil.isNotEmpty(resultItems.get("siteData"))) {
            siteData = resultItems.get("siteData");
        } else if (ObjectUtil.isNotEmpty(resultItems.get("zbData"))){
            zbData.add(resultItems.get("zbData"));
        }
        System.err.println(JSONObject.toJSONString(siteData));
        System.err.println("长度"+siteData.size());
        System.err.println(JSONObject.toJSONString(zbData));
        System.err.println("长度"+zbData.size());
        if (ObjectUtil.isNotEmpty(resultItems.get("finish"))) {
            System.err.println("爬虫结束");
        }
    }
}
